<?php
/*
 * Form - Ung vien dang ky
 */
?>
<?php

class UngvienDangkyForm extends CFormModel {

    public $tendangnhap;
    public $matkhau;
    public $re_matkhau;
    public $email;
    public $tengoi;
    public $gioitinh;
    public $ngaysinh;
    public $quocgia;
    public $thanhpho;
    public $verifyCode;

    /**
     * Declares the validation rules.
     * The rules state that username and password are required,
     * and password needs to be authenticated.
     */
    public function rules() {
        return array(
            // reules required
            array('tendangnhap, matkhau, re_matkhau, email, tengoi, gioitinh, ngaysinh, quocgia, thanhpho', 'required'),
            // compare password
            array('re_matkhau','compare', 'compareAttribute' => 'matkhau'),
            // email has to be a valid email address
            array('email', 'email'),
            // password needs to be unique
            array('email', 'unique', 'className' => 'Nguoitimviec'),
            // username needs to be unique
            array('tendangnhap','unique', 'className' => 'Nguoitimviec'),
            // verifyCode needs to be entered correctly
            //array('verifyCode', 'captcha', 'allowEmpty' => !CCaptcha::checkRequirements()),
        );
    }

    /**
     * Declares attribute labels.
     */
    public function attributeLabels() {
        return array(
            'rememberMe' => 'Ghi nhớ đăng nhập',
            'tendangnhap' => 'Tên đăng nhập',
            'matkhau' => 'Mật khẩu',
            'email' => 'Email',
            'tengoi'=> 'Họ và tên',
            'gioitinh' => 'Giới tính',
            'ngaysinh'=> 'Ngày sinh',
            'quocgia' => 'Quốc gia',
            'thanhpho' => 'Thành phố',
            'verifyCode'=>'Mã xác nhận',
            're_matkhau'=>'Nhập lại mật khẩu'
        );
    }
    
    public function getQuocgia(){
        $quocgia =  Quocgia::model()->findAll();
        
        if(count($quocgia) > 0){
            foreach($quocgia as $key => $value){
                $quocgias[$value->id] =  $value->name;
            }
            return $quocgias;
        }
              
        return false;
    }
    
    public function getThanhpho($quocgia_id = 1){
        $thanhpho = Thanhpho::model()->findAllByAttributes(array('quocgia_id' => $quocgia_id));
        if(count($thanhpho) > 0){
            foreach($thanhpho as $key => $value){
                $thanhphos[$value->id] =  $value->name;
            }
            if($_GET['ajax']){
                echo json_encode($thanhphos);
            }
               
            return $thanhphos;
        }
              
        return false;
    }

}
?>
